package univer.oko.print;

import java.awt.*;
import java.awt.print.*;

/**
 * @author Eduard Dudar
 *         23.04.2005
 *         Copyright 2005
 */
public abstract class Printer implements Printable {
    protected PageFormat page = null;
    protected Paper paper = null;
    protected PrinterJob printer = null;

    public Printer() {
        this.printer = PrinterJob.getPrinterJob();
        this.configurePaper();
        this.configurePage();
    }

    protected void setPrintable(Printable printer, PageFormat pageFormat) {
        this.printer.setPrintable(printer, pageFormat);
    }

    public boolean print() throws PrinterException {
        printer.print();
        return true;
    }

    protected void configurePaper() {
        this.paper = new Paper();
    }

    protected void configurePage() {
        if (this.paper != null) {
            this.page = this.printer.defaultPage();
            this.page.setPaper(this.paper);
        }
    }

    public abstract int print(Graphics g, PageFormat pf, int pageIndex);
}
